<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
    function sumAll(arr) {
        var start = arr[0];
        var end = arr[1];
        if (start > end) {
            var temp = start;
            start = end;
            end = temp;
        }
        return (end - start + 1) * (start + end) / 2;
    }
    document.write(sumAll([1, 4]));

</script>
</body>
</html>